package friot.service.user.controller;

import friot.feign.clients.IDeviceClient;
import friot.model.iot.vo.IotDeviceVo;
import friot.model.user.dtos.UserLoginDto;
import friot.service.user.service.UserService;
import friot.utils.tools.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 设备云登录相关
 *
 * @author He Kuntao
 * @date 2023/11/24 15:35
 */
@Slf4j
@RestController
@RequestMapping("/api/account")
public class UserLoginController {
    @Resource
    private UserService userService;
    @Resource
    private IDeviceClient iDeviceClient;

    @GetMapping("/test")
    public void test() {
        Result result = iDeviceClient.listDeviceByUserId("2");
        log.info("result: {}", result);
    }


    /**
     * 注册账号
     */
    @PostMapping("/register")
    public Result register(@RequestBody UserLoginDto dto) {
        log.info("register: {}", dto);
        userService.registerCount(dto);
        return Result.success();
    }

    /**
     * 登录账号
     */
    @PostMapping("/login")
    public Result login(@RequestBody UserLoginDto dto) {
        log.info("login: {}", dto);
        String jwt = userService.login(dto);
        return Result.success(jwt);
    }

}
